﻿package component.tree.web.view;

import component.tree.util.ConfigUtil;

public class HtmlView {
	protected String context;
	
	protected void setLineBreak(StringBuffer sb){
		sb.append("\n");
	}
	
	protected void setTitleHtml(StringBuffer sb,String title){
		sb.append("<title>");
		sb.append(title);
		sb.append("</title>");
		this.setLineBreak(sb);
	}
	
	protected void setHeadHtml(StringBuffer sb,String title,String importLib){
		sb.append("<head>");
		this.setLineBreak(sb);
		sb.append("<title>"+title+"</title>");
		this.setLineBreak(sb);
		sb.append("<style>");
		sb.append("</style>");
		sb.append("</head>");
		this.setLineBreak(sb);
	}
	
	protected void setButtonHtml(StringBuffer sb,String value,String onClick){
		sb.append("<input type='button' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	protected void setButtonHtml(StringBuffer sb,String id,String value,String onClick){
		sb.append("<input type='button' id='"+id+"' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	protected void setButtonHtml(StringBuffer sb,String id,String name,String value,String onClick){
		sb.append("<input type='button' id='"+id+"' name='"+name+"' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	
	protected void startHtml(StringBuffer sb){
		sb.append("<html>");
		this.setLineBreak(sb);
	}
	protected void endHtml(StringBuffer sb){
		sb.append("</html>");
	}
	
	protected void startBody(StringBuffer sb,String attribute){
		sb.append("<body ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endBody(StringBuffer sb){
		sb.append("</body>");
		this.setLineBreak(sb);
	}
	
	protected void startForm(StringBuffer sb,String attribute){
		sb.append("<form ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endForm(StringBuffer sb){
		sb.append("</form>");
		this.setLineBreak(sb);
	}
	
	protected void startDiv(StringBuffer sb,String attribute){
		sb.append("<div ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endDiv(StringBuffer sb){
		sb.append("</div>");
		this.setLineBreak(sb);
	}
	
	protected void startTable(StringBuffer sb,String attribute){
		sb.append("<table ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTable(StringBuffer sb){
		sb.append("</table>");
		this.setLineBreak(sb);
	}
	
	protected void startTr(StringBuffer sb,String attribute){
		sb.append("<tr ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTr(StringBuffer sb){
		sb.append("</tr>");
		this.setLineBreak(sb);
	}
	
	protected void startTd(StringBuffer sb,String attribute){
		sb.append("<td ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTd(StringBuffer sb){
		sb.append("</td>");
		this.setLineBreak(sb);
	}
	
	protected void startA(StringBuffer sb,String attribute){
		sb.append("<a ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endA(StringBuffer sb){
		sb.append("</a>");
		this.setLineBreak(sb);
	}
	
	protected void startScript(StringBuffer sb){
		this.setLineBreak(sb);
		sb.append("<SCRIPT LANGUAGE='JavaScript'>");
		this.setLineBreak(sb);
		sb.append("<!--");
		this.setLineBreak(sb);
	}
	protected void endScript(StringBuffer sb){
		this.setLineBreak(sb);
		sb.append("//-->");
		this.setLineBreak(sb);
		sb.append("</SCRIPT>");
		this.setLineBreak(sb);
	}
	
	protected void startMethod(StringBuffer sb,String methodName,String methodArgs){
		sb.append("function " + methodName + "(" + methodArgs + "){");
		this.setLineBreak(sb);
	}
	protected void endMethod(StringBuffer sb){
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void writeMethod(StringBuffer sb,String methodName,String content){
		sb.append("function " + methodName + "(){");
		this.setLineBreak(sb);
		sb.append(content);
		this.setLineBreak(sb);
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void setTry(StringBuffer sb){
		sb.append("try{");
		this.setLineBreak(sb);
	}
	protected void setCatch(StringBuffer sb,String error){
		sb.append("}catch(e){");
		this.setLineBreak(sb);
		sb.append(error);
		this.setLineBreak(sb);
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void windowClose(StringBuffer sb){
		sb.append("window.close();");
		this.setLineBreak(sb);
	}
	
	//获取js对象开始
	
	
	//获取js对象结束

	public String getContext() {
		return context;
	}

	public void setContext(String context) {
		this.context = context;
	}
	
}
